﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace _14Net8AspNetCore_Authorization.Controllers
{
    /// <summary>
    /// 页面权限 控制器
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class PagePermissionController : ControllerBase
    {
        public PagePermissionController(IAuthorizationService authorizationService)
        {
            AuthorizationService = authorizationService;
        }

        /// <summary>
        /// 鉴权Service
        /// </summary>
        public IAuthorizationService AuthorizationService { get; set; }

        /// <summary>
        /// 页面鉴权方法
        /// </summary>
        [HttpPost]
        public async Task<AuthorizationResult> PagePermission(string UserPermission)
        {
            AuthorizationResult authorizationResult = await AuthorizationService.AuthorizeAsync(HttpContext.User, UserPermission);
            return authorizationResult;
        }
    }
}
